<?php $this->load->view("layout/header_data_form");?>
<script type="text/javascript" src="<?php echo js_link('jquery.js');?>"></script>
<script type="text/javascript" src="<?php echo js_link('jquery.highlightFade.js');?>"></script>
<script type="text/javascript">
function addFormField() {
	var id = document.getElementById("hidd").value;
	$("#divTxt").append("<div id='row" + id + "' class='width'><input type='text' size='25' name='amount[]' id='amount" + id + "' class='field' /> <input type='text' size='25' name='years[]' id='years" + id + "' class='field' /><input name='id[]' type='hidden'/><a href='#' onClick='removeFormField(\"#row" + id + "\"); return false;' class='delete'>Delete</a></div>");
	
	
	$('#row' + id).highlightFade({
		speed:1000
	});
	
	id = (id - 1) + 2;
	document.getElementById("hidd").value = id;
}

function removeFormField(id) {
	$(id).remove();
}
</script>

<script type="text/javascript">

function showhide(divid, state){
document.getElementById(divid).style.display=state
}

</script>
<?php $this->load->view('layout/logo');?>

<div id="wrap">
    <table border="0" cellpadding="5" cellspacing="0">
      <tr>
        <td width="500" align="left" valign="top">
        <form id="form1" name="form1" method="post" action="">
        <table border="0" cellpadding="7" cellspacing="0">
          <?php 
          if(!$rows):
          ?>
          <tr>
            <td align="right" valign="top"><strong>Saving1:</strong></td>
            <td valign="top"><table border="0" cellpadding="3" cellspacing="0">
                <tr>
                  <td width="133"><input name="amount[]" type="text" class="field" id="textfield" value="Amount to Save" size="25" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" /></td>
                  <td width="133"><input name="years[]" type="text" class="field" id="textfield9" value="Years to Go" size="25" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
                    <a href="#" onclick="addFormField(); return false;"></a> 
                    <input type="hidden" name="id[]" value=""/>
                    </td>
                  <td width="29" align="left"><a href="#" onclick="addFormField(); return false;"><img src="<?php echo img_link('add.gif');?>" alt="Add" border="0" /></a></td>
                </tr>
              </table>
                <input type="hidden" id="hidd" value="hidd" />
                <div id="divTxt"></div></td>
          </tr>
          <?php 
          else:
          ?>
          <?php 
          foreach($rows as $k => $v):
          	if($k==0):
          ?>
          		<tr>
	            <td align="right" valign="top"><strong>Saving:</strong></td>
	            <td valign="top"><table border="0" cellpadding="3" cellspacing="0">
	                <tr>
	                  <td width="133"><input value="<?php echo $v['amount_to_save'];?>" name="amount[]" type="text" class="field" id="textfield" value="Amount to Save" size="25" onfocus="if(this.value=='') this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" /></td>
	                  <td width="133"><input value="<?php echo $v['years_to_go'];?>" name="years[]" type="text" class="field" id="textfield9" value="Years to Go" size="25" onfocus="if(this.value=='') this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
	                  <input type="hidden" name="id[]" value="<?php echo $v['id'];?>"/>
	                    <a href="#" onclick="addFormField(); return false;"></a> </td>
	                  <td width="29" align="left"><a href="#" onclick="addFormField(); return false;"><img src="<?php echo img_link('add.gif');?>" alt="Add" border="0" /></a></td>
	                </tr>
	              </table>
	                <input type="hidden" id="hidd" value="<?php echo($k);?>" />
	                <div id="divTxt">
	          
	          <?php elseif($k+1 == count($rows)):?>
	          <div id='row<?php echo $k;?>' class='width'>
	          	<input type='text' size='25' value="<?php echo $v['amount_to_save'];?>" name='amount[]' id='amount" + id + "' class='field' /> 
	          	<input type='text' size='25' value="<?php echo $v['years_to_go'];?>" name='years[]' id='years" + id + "' class='field' />
	          	<input type="hidden" name="id[]" value="<?php echo $v['id'];?>"/>
	          	<a href='#' onClick='removeFormField("#row<?php echo $k;?>"); return false;' class='delete'>Delete</a>
	          	</div>
	          </div></td></tr>
	          <?php else:?>
	          	<div id='row<?php echo $k;?>' class='width'>
	          	<input type='text' value="<?php echo $v['amount_to_save'];?>" size='25' name='amount[]' id='amount" + id + "' class='field' /> 
	          	<input type='text' value="<?php echo $v['years_to_go'];?>" size='25' name='years[]' id='years" + id + "' class='field' />
	          	<input type="hidden" name="id[]" value="<?php echo $v['id'];?>"/>
	          	<a href='#' onClick='removeFormField("#row<?php echo $k;?>"); return false;' class='delete'>Delete</a>
	          	</div>
	          <?php endif;?>
          <?php 
          endforeach;
          ?>
          <?php 
          endif;
          ?>
          <tr>
            <td align="right" valign="top">&nbsp;</td>
            <td valign="top">
            	<input name="btnCalculate" type="submit" class="large button green" value="Calculate"/>
            	<input type="hidden" name="submit" value="0"/>
            </td>
          </tr>
          <tr>
            <td align="right" valign="top">&nbsp;</td>
            <td valign="top">&nbsp;</td>
          </tr>
        </table>
        </td>
      </tr>
      <tr>
        <td align="left" valign="top">
        
                <div id="graph" style="display:<?php echo(isset($_POST) ? 'block' : 'none');?>">
<br />
<br />
 <?php $this->load->view('savings/chart');?>
            <table border="0" cellpadding="7" cellspacing="0">
	              <tr>
	                <td align="left"><strong>Explanation:</strong></td>
	              </tr>
	              <tr>
	                <td align="left"><textarea name="explanation" cols="60" rows="6" class="field" id="textfield3"><?php echo(isset($exp) && $exp ? $exp->explanation : '');?></textarea></td>
	              </tr>
	              <tr>
	                <td align="right">
	                	<input name="btnSubmit" type="submit" class="large button red" value="submit"/>
	                	<input type="hidden" name="submit" value="1"/>
	                </td>
	              </tr>
	          </table>
          </form>

<br />
</div>
        
        </td>
      </tr>
      <tr>
        <td align="left" valign="top"><a href="JavaScript:window.close();"><img src="<?php echo img_link('cwindow.jpg');?>" alt="Close Window" width="82" height="15" border="0" /></a></td>
      </tr>
    </table>
  
  
  
</div>
<?php $this->load->view("layout/footer_data_form");?>